package com.hjxr.sysadmin.zsj.controller;

import java.util.List;

import com.hjxr.sysadmin.zsj.domain.ZIndustry;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hjxr.framework.aspectj.lang.annotation.Log;
import com.hjxr.framework.aspectj.lang.enums.BusinessType;
import com.hjxr.sysadmin.zsj.domain.Location;
import com.hjxr.sysadmin.zsj.service.ILocationService;
import com.hjxr.sysadmin.web.controller.BaseController;
import com.hjxr.framework.web.domain.AjaxResult;
import com.hjxr.sysadmin.uitl.poi.ExcelUtil;
import com.hjxr.sysadmin.web.page.TableDataInfo;

/**
 * 区域信息Controller
 *
 * @author zc
 * @date 2021-04-12
 */
@Api("区域信息管理")
@RestController
@RequestMapping("/location")
public class LocationController extends BaseController
{
    @Autowired
    private ILocationService locationService;

    /**
     * 查询区域信息列表
     */
    @ApiOperation("查询区域信息列表")
    @PreAuthorize("@ss.hasPermi('system:location:list')")
    @GetMapping("/list")
    public TableDataInfo list(Location location)
    {
        startPage();
        List<Location> list = locationService.selectLocationList(location);
        return getDataTable(list);
    }

    /**
     * 导出区域信息列表
     */
    @ApiOperation("导出区域信息列表")
    @PreAuthorize("@ss.hasPermi('system:location:export')")
    @Log(title = "导出区域信息列表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Location location)
    {
        List<Location> list = locationService.selectLocationList(location);
        ExcelUtil<Location> util = new ExcelUtil<Location>(Location.class);
        return util.exportExcel(list, "location");
    }

    /**
     * 获取区域信息详细信息
     */
    @ApiOperation("获取区域信息详细信息")
    @PreAuthorize("@ss.hasPermi('system:location:query')")
    @GetMapping(value = "/{locationId}")
    public AjaxResult getInfo(@PathVariable("locationId") Long locationId)
    {
        return AjaxResult.success(locationService.selectLocationById(locationId));
    }

    /**
     * 新增区域信息
     */
    @ApiOperation("新增区域信息")
    @PreAuthorize("@ss.hasPermi('system:location:add')")
    @Log(title = "新增区域信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Location location)
    {
        if (locationService.hasByNameAndYear(location.getNd(), location.getLocationName()))
        {
            return AjaxResult.error("已存在当前年数据,请前往修改");
        }
        return toAjax(locationService.insertLocation(location));
    }

    /**
     * 修改区域信息
     */
    @ApiOperation("修改区域信息")
    @PreAuthorize("@ss.hasPermi('system:location:edit')")
    @Log(title = "修改区域信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Location location)
    {
        return toAjax(locationService.updateLocation(location));
    }

    /**
     * 删除区域信息
     */
    @ApiOperation("删除区域信息")
    @PreAuthorize("@ss.hasPermi('system:location:remove')")
    @Log(title = "删除区域信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{locationIds}")
    public AjaxResult remove(@PathVariable Long[] locationIds)
    {
        return toAjax(locationService.deleteLocationByIds(locationIds));
    }

    /**
     * 获取区域主导产业信息详
     */
    @ApiOperation("获取区域主导产业信息")
    @GetMapping(value = "/industry/{locationName}")
    public AjaxResult selectIndustryById(@PathVariable("locationName") String locationName)
    {
        return AjaxResult.success(locationService.selectIndustryByName(locationName));
    }

    /**
     * 新增区域主导产业信息
     */
    @ApiOperation("新增区域主导产业信息")
    @Log(title = "新增区域主导产业信息", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/addindustry")
    public AjaxResult insertIndustry(@RequestBody ZIndustry zIndustry)
    {
        return toAjax(locationService.insertIndustry(zIndustry));
    }

    /**
     * 修改区域主导产业信息
     */
    @ApiOperation("修改区域主导产业信息")
    @Log(title = "修改区域主导产业信息", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/editindustry")
    public AjaxResult updateIndustry(@RequestBody ZIndustry zIndustry)
    {
        return toAjax(locationService.updateIndustry(zIndustry));
    }
}
